package com.example.administrator.gplineview;

import android.content.Intent;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.util.Log;
import android.view.View;
import android.view.WindowManager;
import android.widget.Button;
import android.widget.ImageView;

import com.example.administrator.gplineview.bitmap_util.BitmapUtil;
import com.fm.openinstall.OpenInstall;
import com.fm.openinstall.listener.AppInstallListener;
import com.fm.openinstall.model.AppData;
import com.fm.openinstall.model.Error;

import butterknife.BindView;
import butterknife.ButterKnife;

public class MainActivity extends AppCompatActivity implements View.OnClickListener, AppInstallListener {

    @BindView(R.id.btn_fund_pic)
    Button mBtnFundPic;
    @BindView(R.id.btn_pull_show)
    Button mBtnPullShow;
    @BindView(R.id.btn_round_view)
    Button mBtnRoundView;
    @BindView(R.id.btn_surface)
    Button mBtnSurface;
    @BindView(R.id.btn_record)
    Button mBtnRecord;
    @BindView(R.id.iv1)
    ImageView mIv1;
    @BindView(R.id.iv2)
    ImageView mIv2;
    @BindView(R.id.iv3)
    ImageView mIv3;
    @BindView(R.id.iv4)
    ImageView mIv4;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main_button);
        ButterKnife.bind(this);
        getWindow().addFlags(WindowManager.LayoutParams.FLAG_SECURE);
        OpenInstall.getInstall(this);

        mBtnFundPic.setOnClickListener(this);
        mBtnPullShow.setOnClickListener(this);
        mBtnRoundView.setOnClickListener(this);
        mBtnSurface.setOnClickListener(this);
        mBtnRecord.setOnClickListener(this);
        Bitmap bm = BitmapFactory.decodeResource(getResources(), R.drawable.ic_launcher);
        Bitmap bitmap = BitmapUtil.getRoundCornerBitmap(bm);
        mIv1.setImageBitmap(bitmap);
        mIv2.setImageBitmap(BitmapUtil.getCircleBitmap(bm));
        mIv3.setImageBitmap(BitmapUtil.getMirrorBitmap(bm));
        mIv4.setImageBitmap(BitmapUtil.getBlurBitmap(bm));
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.btn_fund_pic:
                startActivity(new Intent(MainActivity.this, FundPictureActivity.class));
                break;
            case R.id.btn_pull_show:
                startActivity(new Intent(MainActivity.this, PullActivity.class));
                break;
            case R.id.btn_round_view:
                startActivity(new Intent(MainActivity.this, RoundViewActivity.class));
                break;
            case R.id.btn_surface:
                startActivity(new Intent(MainActivity.this, MySurfaceViewActivity.class));
                break;
            case R.id.btn_record:
                startActivity(new Intent(MainActivity.this, RecordingActivity.class));
        }
    }


    @Override
    public void startActivity(Intent intent) {
        super.startActivity(intent);
        overridePendingTransition(R.anim.right_in, R.anim.left_out);
    }

    @Override
    public void onInstallFinish(AppData appData, Error error) {
        if (error == null) {
            //获取渠道数据
            Log.d("mtag", "channel = " + appData.getChannel());
            //获取个性化安装数据
            Log.d("mtag", "install = " + appData.getData());
        } else {
            Log.d("mtag", "error : " + error.toString());
        }
    }
}
